//
//  HLCourseDiscuss.m
//  HLAerospace
//
//  Created by hulian-ios on 17/9/11.
//  Copyright © 2017年 hulian-LB. All rights reserved.
//

#import "HLCourseDiscuss.h"

@implementation HLCourseDiscuss

- (CGFloat)cellHeight
{
    if (!_cellHeight) {

//         CGSize contentSize = [[self.title_content stringByRemovingPercentEncoding] boundingRectWithSize:CGSizeMake(ScreenWidth - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName :[UIFont systemFontOfSize:IS_IPHONE_5 ? 14:(kMainTitleFontSize + 2)] } context:nil].size;
        CGSize contentSize = [self.title_content  boundingRectWithSize:CGSizeMake(ScreenWidth - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName :[UIFont systemFontOfSize:IS_IPHONE_5 ? 14:(kMainTitleFontSize + 2)] } context:nil].size;
        _cellHeight = contentSize.height + 91;
    }
    return _cellHeight;
}

- (NSString *)time
{
    // 日期格式化类
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    
    // NSString -> NSDate
    NSDate *createdAtDate = [fmt dateFromString:_time];
    
    // 比较 返回时间 和【手机当前时间】的差值
    NSDateComponents *cmps = [createdAtDate intervalToNow];
    
    if (createdAtDate.isThisYear) {
        if (createdAtDate.isToday) { // 今天
            if (cmps.hour >= 1) { // 时间差距 >= 1小时
                return [NSString stringWithFormat:@"%zd小时前", cmps.hour];
            } else if (cmps.minute >= 1) { // 1分钟 =< 时间差距 <= 59分钟
                return [NSString stringWithFormat:@"%zd分钟前", cmps.minute];
            } else {
                return @"刚刚";
            }
        } else if (createdAtDate.isYesterday) { // 昨天
            fmt.dateFormat = @"昨天 HH:mm";
            return [fmt stringFromDate:createdAtDate];
        } else { // 今年的其他时间
            fmt.dateFormat = @"MM-dd HH:mm";
            return [fmt stringFromDate:createdAtDate];
        }
    } else { // 非今年
        return _time;
    }
}


@end
